﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using cogency.representation;

namespace cogency.languages
{
    public class CodeWriterContext
    {
        public readonly string RootDirectory;
        public readonly string RootNamespace;
        public readonly string CommonHeader;
        public readonly CodeTargetType CodeTargetType;
        public readonly RNamespace Namespace;
        public StreamWriter Output;
        public Indent Indent;

        public CodeWriterContext(
            string rootDirectory, 
            string rootNamespace, 
            CodeTargetType codeTargetType, 
            RNamespace ns,
            string commonHeader)
        {
            RootDirectory = rootDirectory;
            RootNamespace = rootNamespace;
            CodeTargetType = codeTargetType;
            Namespace = ns;
            CommonHeader = commonHeader;
            Indent = new Indent();
        }

        protected CodeWriterContext(
            CodeWriterContext objectSrc)
        {
            RootDirectory = objectSrc.RootDirectory;
            RootNamespace = objectSrc.RootNamespace;
            CodeTargetType = objectSrc.CodeTargetType;
            Namespace = objectSrc.Namespace;
            CommonHeader = objectSrc.CommonHeader;
            Indent = new Indent();
        }

        
        protected void AppendFormat(string pattern, params object[] args)
        {
            Output.Write(string.Format(pattern, args));
        }

        protected void Append(RDeclaration decl, string pattern)
        {
            Output.Write(string.Format(pattern, Indent, decl.Name, decl.ReferencedName));
        }

        protected void AppendIndented(string line)
        {
            Output.Write(Indent);
            Output.Write(line);
        }

        protected void Newline()
        {
            Output.WriteLine();
        }
    }
}
